/**
 * Class containing the weights strategy.
 * @author	081028AW
 */
public class StrategyWeights extends Strategy
{
	/**
	* Encoding for weights strategy.
	*/

	public String simpleStratMoves;
	public int currMove;
	public double finalMove;
	public String simpleStrat;

	public double currIteration;
	public double mostInARowC;
	public double mostInARowD;
	// Partner Info
	public double numPartnerC;
	public double numPartnerD;
	public double numPartnerCinRow;
	public double numPartnerDinRow;
	public double lastPartnerMoves[];
	public double lastPartnerMoves1;
	public double lastPartnerMoves2;
	// My Info
	/*public int numMyC;
	public int numMyD;
	public int numMyCinRow;
	public int numMyDinRow;
	public int lastMyMoves[5];*/
	// Weights
	public double a;
	public double b;
	public double c;
	public double d;
	public double e;
	public double f;
	public double g;

	//public int runningCorD = 0;
	

	// 0 = defect, 1 = cooperate

	public StrategyWeights()
	{
		name = "Weights";
		currMove = 0;
		finalMove = 1;
		
		currIteration = 0;
		numPartnerC = 0;
		numPartnerD = 0;
		numPartnerCinRow = 0;
		numPartnerDinRow = 0;
		lastPartnerMoves1 = 0;
		lastPartnerMoves2 = 0;
		//lastPartnerMoves[2];
		////lastPartnerMoves[1] = 0;
		////lastPartnerMoves[0] = 0;
		//lastPartnerMoves[2] = 0;
		//lastPartnerMoves[3] = 0;
		//lastPartnerMoves[4] = 0;

	}  /* StrategyWeights */

	public double getCurrWeights(int currVal)
	{
		return currVal;
	}

	public int nextMove()
	{

		System.out.println("a: " + a + " b: " + b + " c: " + c + " d: " + d + " e: " + e + " f: " + f + " g: " + g);
		a /= 1023;
		b /= 1023;
		c /= 1023;
		d /= 1023;
		e /= 1023;
		f /= 1023;
		g /= 1023;

		// Store last 5 moves
		lastPartnerMoves[0] = lastPartnerMoves[1];
		lastPartnerMoves[1] = opponentLastMove;
		//lastPartnerMoves[2] = lastPartnerMoves[3];
		//lastPartnerMoves[3] = lastPartnerMoves[4];
		//lastPartnerMoves[4] = opponentLastMove;
		// Increment overall D count
		if(opponentLastMove == 0)
		{
			numPartnerD++;
		}
		// Increment overall C count
		if(opponentLastMove == 1)
		{
			numPartnerC++;
		}
		// Set up numbers for C or D in row
		if(currIteration == 0)
		{
			if(opponentLastMove == 0)
			{
				numPartnerDinRow++;
				numPartnerCinRow = 0;
			}
			else
			{
				numPartnerCinRow++;
				numPartnerDinRow = 0;
			}
		}
		else
		{
			if(lastPartnerMoves[0] == lastPartnerMoves[1] && lastPartnerMoves[1] == 0)
			{
				numPartnerDinRow++;
				numPartnerCinRow = 0;
			}
			else if(lastPartnerMoves[0] == lastPartnerMoves[1] && lastPartnerMoves[1] == 1)
			{
				numPartnerCinRow++;
				numPartnerDinRow = 0;
			}
			else if(lastPartnerMoves[0] != lastPartnerMoves[1] && lastPartnerMoves[0] == 0)
			{
				numPartnerCinRow++;
				numPartnerDinRow = 0;
			}
			else if(lastPartnerMoves[0] != lastPartnerMoves[1] && lastPartnerMoves[0] == 1)
			{
				numPartnerDinRow++;
				numPartnerCinRow = 0;
			}
		}
		if(mostInARowD < numPartnerDinRow)	
		{
			mostInARowD = numPartnerDinRow;
		}
		else if(mostInARowC < numPartnerCinRow)
		{
			mostInARowC = numPartnerCinRow;
		}

		if(lastPartnerMoves[0] == 0)
		{
			lastPartnerMoves[0] = -1;
		}
		else if(lastPartnerMoves[1] == 0)
		{
			lastPartnerMoves[1] = -1;
		}
	
		finalMove = a + b*(numPartnerC/currIteration) + c*(numPartnerD/currIteration) + d*(numPartnerCinRow/mostInARowC) + e*(numPartnerDinRow/mostInARowD) + f*lastPartnerMoves[0] + g*lastPartnerMoves[1];
		
		if(finalMove >= 0.5)
		{
			currMove = 1;
		}
		else
		{
			currMove = 0;
		}

		if(lastPartnerMoves[0] == -1)
		{
			lastPartnerMoves[0] = 0;
		}
		else if(lastPartnerMoves[1] == -1)
		{
			lastPartnerMoves[1] = 0;
		}
		

		//System.out.println("output: " + simpleStratMoves.charAt(currMove) + ", moveNum: " + moveNum);
	
		currIteration++;

		return currMove;

    }  /* nextMove */

  }  /* class StrategyWeights */

